﻿@model GAE_PI.Models.DetailActivityModel

@{
    ViewBag.Title = "Nouvelle Activite";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Nouvelle Activite</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script>
    $(document).ready(function () {
        $('#imagesAdd').click(function () {
            var num = $('.clonedImage').length - 1; // how many "duplicatable" input fields we currently have
            var newNum = new Number(num + 1);      // the numeric ID of the new input field being added

            // create the new element via clone(), and manipulate it's ID using newNum value
            var newElem = $('#images' + num).clone().attr('id', 'images' + newNum);

            // manipulate the name/id values of the input inside the new element
            newElem.children(':first').attr('id', 'images_' + newNum + '_').attr('name', 'images[' + newNum + ']');

            // insert the new element after the last "duplicatable" input field
            $('#images' + num).after(newElem);

            // enable the "remove" button
            $('#imagesDel').removeAttr("disabled");   
        });

        $('#imagesDel').click(function () {
            var num = $('.clonedImage').length - 1; // how many "duplicatable" input fields we currently have
            $('#images' + num).remove();     // remove the last element

            // enable the "add" button
            $('#imagesAdd').removeAttr("disabled");   

            // if only one element remains, disable the "remove" button
            if (num == 1)
                $('#imagesDel').attr('disabled', 'disabled');
        });
        if ($('.clonedImage').length == 1)
            $('#imagesDel').attr('disabled', 'disabled');


        $('#datesAdd').click(function () {
            var num = $('.clonedDate').length - 1; // how many "duplicatable" input fields we currently have
            var newNum = new Number(num + 1);      // the numeric ID of the new input field being added

            // create the new element via clone(), and manipulate it's ID using newNum value
            var newElem = $('#Dates' + num).clone().attr('id', 'Dates' + newNum);

            // manipulate the name/id values of the input inside the new element
            newElem.children(':first').attr('id', 'Dates_' + newNum + '_').attr('name', 'Dates[' + newNum + ']');

            // insert the new element after the last "duplicatable" input field
            $('#Dates' + num).after(newElem);

            // enable the "remove" button
            $('#datesDel').removeAttr("disabled");   
        });

        $('#datesDel').click(function () {
            var num = $('.clonedDate').length - 1; // how many "duplicatable" input fields we currently have
            $('#dates' + num).remove();     // remove the last element

            // enable the "add" button
            $('#datesAdd').removeAttr("disabled");   

            // if only one element remains, disable the "remove" button
            if (num == 1)
                $('#datesDel').attr('disabled', 'disabled');
        });
        if ($('.clonedDate').length == 1)
            $('#datesDel').attr('disabled', 'disabled');

    });
</script>
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Détails de la nouvelle activité</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Nom)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Nom)
            @Html.ValidationMessageFor(model => model.Nom)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.MinInscription)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MinInscription)
            @Html.ValidationMessageFor(model => model.MinInscription)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.MaxInscription)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MaxInscription)
            @Html.ValidationMessageFor(model => model.MaxInscription)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Prix)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Prix)
            @Html.ValidationMessageFor(model => model.Prix)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Responsables)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Responsables)
            @Html.ValidationMessageFor(model => model.Responsables)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>


        <div class="display-label">Images *</div>
        <div id="images0" class="display-field clonedImage">
            <input class="text-box single-line" id="images_0_" name="images[0]" type="text" />
        </div>
        <div>
            <input type="button" id="imagesAdd" value="Ajouter une image" />
            <input type="button" id="imagesDel" value="Supprimer une image" />
        </div>

        <br />
        <div class="display-label">Dates *</div>
        <div id="Dates0" class="display-field clonedDate">
            <input class="text-box single-line" id="Dates_0_" name="Dates[0]" type="text" />
        </div>
        <div>
            <input type="button" id="datesAdd" value="Ajouter une date" />
            <input type="button" id="datesDel" value="Supprimer une date" />
        </div>
        <p>
            <input type="submit" value="Valider" />
            @Html.ActionLink("Annuler", "ConsulterActivites", "ConsulterActivites", null,new { @class = "button" })
        </p>
    </fieldset>
}
